
preserve

* Keep one row per enterprise
keep if wave_midline == 1 // non-missing for first set of 1,406 rows


*------------------------------------------------------------------------------------
* Table A2 -- Baseline Summary Stats
*------------------------------------------------------------------------------------


* Knowledge of aid-sharing
gen knows_aidsharing = .
replace knows_aidsharing = 1 	if b_f15 == 1
replace knows_aidsharing = 0 	if (b_f15 == 2 | b_f15 == .)
la var knows_aidsharing "Aware of Aid-Sharing"

*Policy prefs
la var bd1_1 "Supports Refugee Hosting"
la var bd1_3 "Supports More Refugees"
la var bd1_5 "Supports Freedom of Movement"
la var bd1_7 "Supports Right to Work"

*Competition
gen pos_econ_effect = b_g1 <= 2 if b_g1 != .
gen rent_increase = b_g15 == 1 | b_g20 == 1 if (b_g15 != . | b_g20 != .)
gen price_increase = b_g16 == 1 | b_g21 == 1 if (b_g16 != . | b_g21 != .)
gen publicgoods_negative = b_g14 == 1 | b_g19 == 1 if (b_g14 != . | b_g19 != .)

la var pos_econ_effect "Refugees Economic Effect is Positive"
la var rent_increase "Refugees Increase Rents"
la var price_increase "Refugees Increase Goods Prices"
la var publicgoods_negative "Refugees Worsen Public Goods"

estpost summarize age edu female tailor experience profit employee

esttab . using "$path/Output/Appendix_A/sum_stats.tex", label nostar nomtitles replace collabels(none) nolines nonumber noobs cells("mean(fmt(a2)) sd(fmt(a2)) count(fmt(%9.0fc))") substitute(\_ _ \$ $) ///
prehead("\begin{table}[h]	\centering	\footnotesize	\caption{Baseline Summary Statistics} \label{tab:sum_stats}	\begin{tabular}{l*{3}{>{\centering\arraybackslash}p{2.2cm}}} \toprule \toprule  & \shortstack{Mean\\~} & \shortstack{Standard\\Deviation} & \shortstack{N\\~} \\") ///
posthead("\cmidrule{2-4} \textit{Owner and Business Characteristics} &&& \\") ///
prefoot("&&& \\") ///
postfoot("")

estpost summarize knows_aidsharing bd1_1 bd1_3 bd1_5 bd1_7

esttab . using "$path/Output/Appendix_A/sum_stats.tex", label nostar nomtitles append collabels(none) nolines nonumber noobs cells("mean(fmt(a2)) sd(fmt(a2)) count(fmt(%9.0fc))") substitute(\_ _ \$ $) ///
prehead("") ///
posthead("\textit{Refugee Integration Policy Views} &&& \\") ///
prefoot("&&& \\") ///
postfoot("")

estpost summarize rent_increase price_increase publicgoods_negative pos_econ_effect

esttab . using "$path/Output/Appendix_A/sum_stats.tex", label nostar nomtitles append collabels(none) nolines nonumber noobs cells("mean(fmt(a2)) sd(fmt(a2)) count(fmt(%9.0fc))") substitute(\_ _ \$ $) ///
prehead("") ///
posthead("\textit{Economic Beliefs} &&& \\") ///
prefoot("") ///
postfoot("\bottomrule \bottomrule \multicolumn{4}{p{0.81\linewidth}}{\footnotesize Source: Baseline surveys of experimental sample in Uganda. Questions on refugees' impacts on prices and public goods are asked about Congolese and Somalis, and are coded as 1 if either answer is \textquotedblleft Yes.\textquotedblright \textquotedblleft Don't Know\textquotedblright\ responses are coded as missing.}  \end{tabular} \\ \end{table}%")


*------------------------------------------------------------------------------------
* Table B1 -- Randomization Balance
*------------------------------------------------------------------------------------

foreach domain_num of numlist 1 111 1111 2 3 4 41 42 51 52 6 61 62 63 7 8 9 10 11 12 13 14 15 16 171 172 {
copydesc e_domain`domain_num' b_domain`domain_num'
local a : variable label b_domain`domain_num'
local a: subinstr local a "\shortstack{" ""
local a: subinstr local a "\" " "
local a: subinstr local a "\" " "
local a: subinstr local a "\" " "
local a: subinstr local a "}" ""
label var b_domain`domain_num' "`a'"
}

local balance_vars age edu experience profit employee knows_aidsharing bd1_1 bd1_3 bd1_5 bd1_7 rent_increase price_increase publicgoods_negative pos_econ_effect b_domain1 b_domain3 b_domain4 b_domain51 b_domain52 b_domain6 b_domain7 b_domain8 b_domain9 b_domain10 b_domain11 b_domain12 b_domain13 b_domain14 b_domain15 b_domain16 b_domain171

forvalues i=1/6{
eststo tb1_`i': estpost summarize `balance_vars' if treatment == `i'
}
eststo p_joint: reg treatment `balance_vars' // to get column titles

local iter = 0
foreach var in `balance_vars' {
	local++ iter
	qui reg `var' i.treatment i.strata, r
	test 2.treatment = 3.treatment = 4.treatment = 5.treatment = 6.treatment = 0
	matrix p_`iter' = r(p)
}

matrix p_joint = (p_1, p_2, p_3, p_4, p_5, p_6, p_7, p_8, p_9, p_10, p_11, p_12, p_13, p_14, p_15, p_16, p_17, p_18, p_19, p_20, p_21, p_22, p_23, p_24, p_25, p_26, p_27, p_28, p_29, p_30, p_31)
mat colnames p_joint = `balance_vars'
estadd matrix p_joint : p_joint
matrix drop p_joint p_1 p_2 p_3 p_4 p_5 p_6 p_7 p_8 p_9 p_10 p_11 p_12 p_13 p_14 p_15 p_16 p_17 p_18 p_19 p_20 p_21 p_22 p_23 p_24 p_25 p_26 p_27 p_28 p_29 p_30 p_31

esttab tb1_5 tb1_4 tb1_3 tb1_2 tb1_1 tb1_6 p_joint using "$path/Output/Appendix_B/randomization_balance.tex", keep(`balance_vars') order(`balance_vars') label nostar nomtitles substitute(\_ _ \$ $) replace collabels(none) nolines nonumber noobs cells("mean(pattern(1 1 1 1 1 1 0) fmt(%9.2f)) p_joint(pattern(0 0 0 0 0 0 1) fmt(2))") ///
prehead("\begin{table}[h]	\centering	\footnotesize	\caption{Randomization Balance} \label{tab:randomization_balance} \begin{tabular}{l*{7}{>{\centering\arraybackslash}p{1.2cm}}} \toprule \toprule  & \shortstack{Mean:\\Labeled\\Grant} & \shortstack{Mean:\\Grant\\Only} & \shortstack{Mean:\\Info\\Only} & \shortstack{Mean:\\Mentored\\by Ref.} & \shortstack{Mean:\\Mentored\\by Ug.} & \shortstack{Mean:\\Control\\~} & \shortstack{Joint\\ $ p $-Value\\~} \\") ///
posthead("\cmidrule{2-8}") ///
prefoot("") ///
postfoot("\bottomrule \bottomrule \multicolumn{8}{p{\linewidth}}{\footnotesize Baseline surveys of experimental sample in Uganda. First six columns show baseline variable means within treatment groups. Column 7 shows $ p $-values from joint $ F $-tests that means are equal in all treatment groups.}  \end{tabular} \\ \end{table}%")

estimates drop tb1_* p_joint

*------------------------------------------------------------------------------------
* Table B2 -- Randomization Balance among those surveyed post-baseline
*------------------------------------------------------------------------------------

bys ent_id: egen ever_surveyed = max(finish_flag)
keep if ever_surveyed == 1

forvalues i=1/6{
eststo tb2_`i': estpost summarize `balance_vars' if treatment == `i'
}
eststo p_joint: reg treatment `balance_vars' // to get column titles

local iter = 0
foreach var in `balance_vars' {
	local++ iter
	qui reg `var' i.treatment i.strata, r
	test 2.treatment = 3.treatment = 4.treatment = 5.treatment = 6.treatment = 0
	matrix p_`iter' = r(p)
}

matrix p_joint = (p_1, p_2, p_3, p_4, p_5, p_6, p_7, p_8, p_9, p_10, p_11, p_12, p_13, p_14, p_15, p_16, p_17, p_18, p_19, p_20, p_21, p_22, p_23, p_24, p_25, p_26, p_27, p_28, p_29, p_30, p_31)
mat colnames p_joint = `balance_vars'
estadd matrix p_joint : p_joint
matrix drop p_joint p_1 p_2 p_3 p_4 p_5 p_6 p_7 p_8 p_9 p_10 p_11 p_12 p_13 p_14 p_15 p_16 p_17 p_18 p_19 p_20 p_21 p_22 p_23 p_24 p_25 p_26 p_27 p_28 p_29 p_30 p_31

esttab tb2_5 tb2_4 tb2_3 tb2_2 tb2_1 tb2_6 p_joint using "$path/Output/Appendix_B/randomization_balance_retain.tex", keep(`balance_vars') order(`balance_vars') label nostar nomtitles substitute(\_ _ \$ $) replace collabels(none) nolines nonumber noobs cells("mean(pattern(1 1 1 1 1 1 0) fmt(%9.2f)) p_joint(pattern(0 0 0 0 0 0 1) fmt(2))") ///
prehead("\begin{table}[h]	\centering	\footnotesize	\caption{Randomization Balance (Among Non-Attriters)} \label{tab:randomization_balance_retain} \begin{tabular}{l*{7}{>{\centering\arraybackslash}p{1.2cm}}} \toprule \toprule  & \shortstack{Mean:\\Labeled\\Grant} & \shortstack{Mean:\\Grant\\Only} & \shortstack{Mean:\\Info\\Only} & \shortstack{Mean:\\Mentored\\by Ref.} & \shortstack{Mean:\\Mentored\\by Ug.} & \shortstack{Mean:\\Control\\~} & \shortstack{Joint\\ $ p $-Value\\~} \\") ///
posthead("\cmidrule{2-8}") ///
prefoot("") ///
postfoot("\bottomrule \bottomrule \multicolumn{8}{p{\linewidth}}{\footnotesize Sample includes all baseline individuals of experimental sample in Uganda who were surveyed in at least one follow-up round. First six columns show baseline variable means within treatment groups. Column 7 shows $ p $-values from joint $ F $-tests that means are equal in all treatment groups.}  \end{tabular} \\ \end{table}%")

estimates drop tb2_* p_joint


restore
